//
// Created by SXL on 2025/8/28.
//


#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
#include <climits>
#include <string>
#include <cmath>
#include <sstream>
#include <set>
#include <unordered_map>
#include <stack>
using namespace std;
#define ll long long



ll add(string &s) {
    ll sum=0;
    for (auto c:s) {
        if (isdigit(c)) {
            sum+=c-'0';
        }else {
            if (c=='a') {
                sum+=10;
            }else if (c=='b') {
                sum+=11;
            }else if (c=='c') {
                sum+=12;
            }else if (c=='d'){
                sum+=13;
            }else if (c=='e') {
                sum+=14;
            }else {
                sum+=15;
            }
        }
    }
    return sum;
}

//https://codefun2000.com/p/P2294  单调栈 确定比较关系 10进制 16进制 字符串 int相互转换 hex
void monostack() {
    int n;
    cin>>n;
    vector<ll>arr(n);
    vector<ll>ans(n,-1);
    stack<int> stk;
    for (int i=0;i<n;i++) {
        int a;
        cin>>a;
        stringstream ss;
        ss<<hex<<a;
        string s=ss.str();
        // cout<<s<<endl;
        arr[i]=add(s);
    }
    // for (auto i:arr) {
    //     cout<<i<<" ";
    // }cout<<endl;
    stk.push(0);
    for (int i=1;i<n;i++) {
        while (!stk.empty()&&arr[stk.top()]<arr[i]) {
            ans[stk.top()]=i;
            stk.pop();
        }
        stk.push(i);
    }
    for (int i=0;i<ans.size();i++) {
        if (i!=ans.size()-1) {
            cout<<ans[i]<<" ";
        }else {
            cout<<ans[i];
        }
    }
}